var bar_001 = echarts.init(document.getElementById('bar-001'));
bar_001.setOption({
    tooltip: {
        trigger: 'axis',
        // axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        //     type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        // },
        formatter(params){
            for(x in params) {
                return params[x].name+ '<br/>'+params[x].seriesName+"："+params[x].value+'<br/>'+"项目金额："+params[x].data.budget;
            }
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: [
        {
            type: 'category',
            data: [],
            axisTick: {
                alignWithLabel: true
            }
        }
    ],
    yAxis: [
        {
            type: 'value'
        }
    ],
    series: [{
        name: '项目数量',
        type: 'bar',
        barWidth: '60%',
        data: []
        // itemStyle: {        //上方显示数值
        //     normal: {
        //         label: {
        //             show: true, //开启显示
        //             position: 'top', //在上方显示
        //             textStyle: { //数值样式
        //                 color: 'black',
        //                 fontSize: 16
        //             }
        //         }
        //     }
        // }
    }]
});

commonBar();

function searchBar() {
    var sdate = $('#sdateBar').val();
    var edate = $('#edateBar').val();
    var param = {sdate:sdate, edate:edate}
    commonBar(param);
}

function commonBar(param = null){
    var date=new Date;
    var y = date.getFullYear()
    $('#sdateBar').val(y+'-01-01');
    $.get('./index.php?a=totalType&m=report|main&d=report', param).done(function (data) {
        data = JSON.parse(data)
        bar_001.setOption({
            xAxis: {
                data: data.name
            },
            series: [{
                data:data.data
            }]
        });
    });
}

bar_001.on('click', function (params) {
    let sdate = $('#sdateBar').val();
    let edate = $('#edateBar').val();
    console.log(sdate,edate);
    let urls = 'report,main,list,type='+params.name+',sdate='+sdate+',edate='+edate;
    addtabs({num:'num329',url:urls,icons:'',name:'采购项目执行汇总'});
});